Question 1

Question 2



Question 1

Explain the four conditions that must hold for deadlock to occur.

The four conditions that must hold for a deadlock to occur are:

- Mutual exclusion: 
Only one process at a time can use a resource. If another process requests the resource, it must be delayed until the resource is released.
- Hold and wait: 
A process holding at least one resource is waiting to acquire additional resources held by other processes.
- No preemption: 
Resources cannot be preempted; they can only be released voluntarily by the process holding them after completing its task.
- Circular wait: 
A set of processes {P0, P1, ..., Pn} exists such that P0 is waiting for a resource held by P1, P1 is waiting for a resource held by P2, ..., 
Pn-1 is waiting for a resource held by Pn, and P0 is waiting for a resource held by P0.



Question 2

Consider a system consisting of four resources of the same type that are shared by three processes, each of which needs at most two resources. 
Show that the system is deadlock-free.

Suppose the system is deadlocked. This implies that each process is holding one resource and waiting for another. 
Since there are three processes and four resources, at least one process must be able to obtain two resources. 
This process will not need more resources, and thus, it will release its resources when done. Therefore, the system cannot be deadlocked.



Question 3

Consider the following snapshot of a system:
Process Allocation
ABCD

Max
ABCD

Available
ABCD
P0 0012 0012 1520
P1 1000 1750
P2 1354 2356
P3 0632 0652
P4 0014 0656
Answer the following questions using the banker's algorithm:

a) What is the content of the matrix Need?

Since Need = Max - Allocation, the content of Need is:

ABCD  
P0: 0000  
P1: 0750  
P2: 1002  
P3: 0020  
P4: 0642

b) Is the system in a safe state?

Yes, the sequence P0, P2, P1, P3, P4 satisfies the safety requirement. This means the system is in a safe state.

c) If a higher priority request made by process P1 for (0,4,2,0) resources, can the request be granted immediately?

Yes, the request can be granted immediately because:

i. (0,4,2,0) ≤ Need(P1) = (0,7,5,0)  
ii. (0,4,2,0) ≤ Available = (1,5,2,0)

The new system state after the allocation is made is still safe, and the sequence P0, P2, P1, P3, P4 satisfies the safety requirement.



Question 4

What is the optimistic assumption made in the deadlock-detection algorithm? How could this assumption be violated?

The optimistic assumption made in the deadlock-detection algorithm is that there will be no circular wait conditions in terms of 
resource allocation and processes making requests for those resources. 
This assumption could be violated if a circular wait does indeed occur in practice, leading to a deadlock situation.